package com.xqboss.apps.controller.consumer;

import com.xqboss.apps.service.consumer.ConsumerTeamUpgradeService;
import com.xqboss.apps.vo.consumer.ConsumerTeamDetailVo;
import com.xqboss.apps.vo.consumer.TeamUpgradesSuccessVo;
import com.xqboss.apps.vo.consumer.TeamUpgradesVo;
import com.xqboss.common.annotation.Log;
import com.xqboss.common.annotation.RepeatSubmit;
import com.xqboss.common.core.controller.BaseController;
import com.xqboss.common.core.domain.R;
import com.xqboss.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;


/**
 * 队伍升级配置(ConsumerTeamUpgradeRule)表控制层
 *
 * @author makejava
 * @since 2023-12-15 14:27:09
 */
@Api(tags = {"队伍升级管理"})
@RestController
@RequestMapping("/apps/consumer/team/upgrade")
public class ConsumerTeamUpgradeController extends BaseController {
    /**
     * 服务对象
     */
    @Autowired
    private ConsumerTeamUpgradeService consumerTeamUpgradeService;

    @ApiOperation("队伍详情")
    @GetMapping(value = "detail/{teamId}")
    public R<ConsumerTeamDetailVo> detail(@PathVariable("teamId")
                                          @ApiParam(value = "队伍id", required = true)
                                          @NotNull(message = "队伍id不能为空！") Long teamId,@RequestParam(required = false,defaultValue = "true") Boolean isAsync) {
        return consumerTeamUpgradeService.teamDetail(teamId, getUserId(),isAsync);
    }

    @ApiOperation("队伍升级详情")
    @GetMapping("/info/{teamId}")
    public R<TeamUpgradesVo> upgradeInfo(@PathVariable("teamId")
                                         @ApiParam(value = "队伍id", required = true)
                                         @NotNull(message = "队伍id不能为空！") Long teamId){
        return consumerTeamUpgradeService.upgradeInfo(teamId,getUserId());
    }

    @RepeatSubmit(interval = 1000, justUrl = true)
    @ApiOperation("队伍升级确认")
    @Log(title = "队伍升级确认", businessType = BusinessType.INSERT)
    @GetMapping("/confirm")
    public R<TeamUpgradesSuccessVo> upgradeConfirm(
                            @ApiParam(name = "teamId",value = "队伍id", required = true) @NotNull(message = "队伍id不能为空！")  Long teamId,
                            @ApiParam(name = "upgradeType", value = "队伍升级类型（0-材料升级；1-普通升级）", required = true)
                            @NotNull(message = "升级类型不能为空！")
                            @Min(0)
                            @Max(1) Integer upgradeType){
        return consumerTeamUpgradeService.upgradeConfirm(teamId,upgradeType,getUserId());
    }

    @RepeatSubmit(interval = 1000, justUrl = true)
    @ApiOperation("退出队伍(队长或主成员)")
    @Log(title = "退出队伍(队长或主成员)", businessType = BusinessType.INSERT)
    @GetMapping(value = "quit/{teamId}")
    public R<String> quit(@PathVariable("teamId") @ApiParam(name = "teamId",value = "队伍id", required = true) @NotNull(message = "队伍id不能为空！")  Integer teamId) {
        return consumerTeamUpgradeService.quit(teamId, getUserId());
    }

    @RepeatSubmit(interval = 1000, justUrl = true)
    @ApiOperation("主成员解除家庭亲属关系")
    @Log(title = "主成员解除家庭亲属关系", businessType = BusinessType.INSERT)
    @GetMapping(value = "secureRelationship")
    public R<String> secureRelationship(@ApiParam(name = "teamId",value = "队伍id", required = true) @NotNull(message = "队伍id不能为空！")  Integer teamId,
                                        @ApiParam(name = "secureUserId",value = "要解除的家庭亲属用户id", required = true) @NotNull(message = "要解除的家庭亲属用户id不能为空！")  Long secureUserId) {
        return consumerTeamUpgradeService.secureRelationship(teamId, secureUserId,getUserId());
    }

    @RepeatSubmit(interval = 1000, justUrl = true)
    @ApiOperation("队长踢人")
    @Log(title = "队长踢人", businessType = BusinessType.INSERT)
    @GetMapping(value = "kickingPeople")
    public R<String> kickingPeople(@ApiParam(name = "teamId",value = "队伍id", required = true) @NotNull(message = "队伍id不能为空！")  Integer teamId,
                                   @ApiParam(name = "kickUserId",value = "要踢用户的用户id", required = true) @NotNull(message = "要踢用户的用户id不能为空！")  Long kickUserId) {
        return consumerTeamUpgradeService.kickingPeople(teamId, kickUserId,getUserId());
    }

}

